package com.example.demo.service.impl;

import com.example.demo.model.User;
import com.example.demo.service.TokenService;
import com.example.demo.util.Const;
import com.example.demo.util.JWTUtil;
import org.springframework.stereotype.Service;


/**
 * @author xdkxlk
 */
@Service
public class TokenServiceImpl implements TokenService {

    @Override
    public String createToken(User user) {
        StringBuffer sb = new StringBuffer();

        String key = this.genTokenKey();
        String jwtToken = JWTUtil.createToken(user, key);

        return jwtToken;
    }

    @Override
    public User checkToken(String token) {
        if (token == null)
            return null;

        return JWTUtil.decodeToken(token, Const.JWT_SECRET);
    }

    @Override
    public void deleteToken(User user) {
        return;
    }

    private String genTokenKey() {
        return Const.JWT_SECRET;
    }

}
